package com.java.base;
import java.util.Scanner;
public class HotelManager {
	static String[][] rooms=new String[12][10];
	static String command;
	static Scanner sca=new Scanner(System.in);
	public static void main(String[] args) {
		for(int i=0;i<rooms.length;i++){
			for(int j=0;j<rooms[i].length;j++){
				rooms[i][j]="empty";
			}
		}
		
		while(true){
			System.out.println("请输入操作命令(search or in or out or quit)：");
			String  str=sca.next();
		    if(str.equals("search")){
					search();		
			}else if(str.equals("in")){
				System.out.println("请输入客人姓名：");
				String name=sca.next();
				System.out.println("请输入客人入住的房间号:");
				int roomNo=sca. nextInt();
				in(name,roomNo);
			}else if(str.equals("out")){
				System.out.println("请输入房间号。");
				int roomNo=sca.nextInt();
				out(roomNo);
			}else {
				System.exit(0);
			}
		
		}

	}
	public static void search(){
		
		for(int i=0;i<rooms.length;i++){
			for(int j=0;j<rooms[i].length;j++){
				System.out.print("   "+((i+1)*100+j+1)+"\t");
				
			}
			System.out.println();
			for(int j=0;j<rooms[i].length;j++){
				System.out.print(rooms[i][j].length()>7?rooms[i][j].substring(0,7):rooms[i][j]+"\t");
			}
			System.out.println("\n");

		}
	

	}
	public static void in(String name,int  roomNo){
		int i=roomNo/100-1;
		int j=roomNo%100-1;
		if(rooms[i][j].equals("empty")){
			rooms[i][j]=name;
			System.out.println("该客人成功入住");
		}else {
			System.out.println("该房间已有人住,请重新输入房间号。。");
			 roomNo=sca. nextInt();
			in(name,roomNo);
		}
		

	}
	public static void out(int roomNo){
		int i=roomNo/100-1;
		int j=roomNo%100-1;
		if(rooms[i][j].equals("empty")){
			System.out.println("该房间为空，无需退房");
		}else {
			rooms[i][j]="empty";
			System.out.println("退房成功");
		}
	}

}
